#include <cstring>
#include <queue>
#include <vector>
#include "graph.h"
using namespace std;
const int P=203;
int n,fa[P],fr[P],dep[P],dis[P],res[P];
vector<int> e[P],bk[P],ifm[P];
vector<bool> been[P];
int dfs1(int father,int depth){
	if(Color()>1) return -1; int u=++n,i;
	fa[u]=father,dep[u]=depth;
	if(u>1) fr[u]=LastRoad()-1;
	e[u].resize(NumberOfRoads());
	bk[u].resize(NumberOfRoads());
	ifm[u].resize(NumberOfRoads());
	been[u].resize(NumberOfRoads());
	for(i=0;i<e[u].size();i++){
		Move(i+1,2),been[u][i]=(Color()==2);
		Move(LastRoad(),Color());
	}
	for(i=0;i<e[u].size();i++){
		Move(i+1,2),e[u][i]=dfs1(u,depth+1);
		bk[u][i]=(e[u][i]==-1)?(LastRoad()-1):fr[e[u][i]];
		Move(bk[u][i]+1,2);
	}
	if(u>1) e[u][fr[u]]=fa[u],been[u][fr[u]]=0;
	return u;
}
void dfs2(int u,int Bs){
	int c=(dep[u])/Bs%3,i,s1;
	for(i=0;i<e[u].size();i++){
		if(!been[u][i]) continue;
		Move(i+1,c+1),s1=Color()-1;
		Move(LastRoad(),Color());
		ifm[u][i]+=s1*Bs;
	}
	for(i=0;i<e[u].size();i++)
		if(e[u][i]>=0&&i!=fr[u]){
			Move(i+1,c+1);
			dfs2(e[u][i],Bs);
			Move(bk[u][i]+1,Color());
		}
}
void bfs(int S){
	int i,s1; queue<int> dl;
	memset(dis,-1,sizeof dis);
	dl.push(S),dis[S]=0;
	while(!dl.empty()){
		s1=dl.front(),dl.pop();
		for(i=0;i<e[s1].size();i++)
			if(dis[e[s1][i]]==-1){
				dl.push(e[s1][i]);
				dis[e[s1][i]]=dis[s1]+1;
			}
	}
}
void Inspect(int R){
	int i,j,k,s1;
	fr[1]=-1,dfs1(0,1);
	for(i=1;i<=n;i*=3) dfs2(1,i);
	for(i=1;i<=n;i++)
		for(j=0;j<e[i].size();j++){
			if(!been[i][j]) continue;
			for(k=dep[i],s1=i;k>ifm[i][j];k--) s1=fa[s1];
			e[i][j]=s1,e[s1][bk[i][j]]=i;
		}
	// Calculate the answer.
	for(i=1;i<=n;i++)
		for(bfs(i),j=1;j<=n;j++)
			if(j!=i) res[dis[j]]++;
	for(i=1;i<=R;i++) Answer(i,res[i]/2);
}
